<?php
class NavigationLinksData_Data {
	
	private $db;
	
	public function __construct(){
		$this->db = new MysqlImproved_Driver();
	}
	
	public function getModuleLink($section){
		$this->db->connect();
		$section = $this->db->escape($section);
		$this->db->prepare(
				"
				SELECT
				modules_settings.module_sitename,
				modules_settings.module_siteurl,
				meta_modules.module_link_title,
				meta_modules.module_link_alt
				FROM
				modules_settings,
				meta_modules
				WHERE
				modules_settings.module_sitename = '$section'
				AND
				meta_modules.module_sitename = '$section'
				;
				"
		);
		$this->db->query();
		$link = "";
		while($link_data = $this->db->fetch('array')){
			$link .= '<a href="';
			$link .= SITE_ROOT.'/'.$link_data['module_siteurl'];
			$link .= '" alt="';
			$link .= $link_data['module_link_alt'];
			$link .= '" title="';
			$link .= $link_data['module_link_title'];
			$link .= '" rel="external">';
			$link .= $link_data['module_sitename'];
			$link .= '</a>';
		}
		return $link;
	}
	
	public function getSectionLink($section){
		$this->db->connect();
		$section = $this->db->escape($section);
		$this->db->prepare(
				"
				SELECT
				category_settings.module_sitename,
				category_settings.category_sitename,
				category_settings.category_siteurl,
				meta_category.category_link_title,
				meta_category.category_link_alt
				FROM
				category_settings,
				meta_category
				WHERE
				category_settings.category_sitename = '$section'
				AND
				meta_category.category_sitename = '$section'
				;
				"
		);
		$this->db->query();
		while($subCategoryLinkData = $this->db->fetch('array')){
		$subCategoryLink ='<a title="';
				$subCategoryLink .= $subCategoryLinkData['category_link_title'];
						$subCategoryLink .= '" alt="';
								$subCategoryLink .= $subCategoryLinkData['category_link_title'];
										$subCategoryLink .= '" href="';
										$subCategoryLink .= SITE_ROOT . '/' . strtolower($subCategoryLinkData['module_sitename']) . '/' . strtolower($subCategoryLinkData['category_siteurl']);
										$subCategoryLink .=  '" rel="external">';
										$subCategoryLink .= $subCategoryLinkData['category_sitename'];
										$subCategoryLink .= '</a>';
										return $subCategoryLink;
				}
			}
}